package thread.ch02;

import thread.annotation.NotThreadSafe;

/**
 * 线程A和B同时执行getInstance，A看的instance是null，并实例化一个新的ExpensiveObject。
 * 同时B也在检查instance是否为null。此时此刻的instance是否为null，这依赖于时序，是无法预期的
 * 
 * @author Administrator
 * 
 */
@NotThreadSafe
public class LazyInitRace {

	private ExpensiveObject instance = null;

	public ExpensiveObject getInstance() {
		if (instance == null) {
			instance = new ExpensiveObject();
		}
		return instance;
	}
}
